<template>
  <div class="message-content">
    <div class="message-title">
      <div class="message-title-text">
        <span class="message-title-text-span">{{ $t("消息") }}</span>
      </div>
    </div>
    <div class="message-list">
      <div
        class="message-list-item"
        @mouseover="onRead(item)"
        v-for="(item, index) in messageList"
        :style="{
          background: item.read ? 'transparent' : '#0085f21a',
        }"
        :key="index"
      >
        <div class="message-list-item-title">
          <div
            class="title"
            :style="{
              color: item.color,
            }"
          >
            <i :class="item.icon"></i>
            <span>{{ item.title }}</span>
          </div>
          <span class="time">{{ item.time.substring(0, 10) }}</span>
        </div>

        <p class="message-list-item-content">
          {{ item.content }}
        </p>
      </div>
    </div>
    <div class="message-btn">
      <div class="message-button">{{ $t("全部已读") }} ({{ read }})</div>
      <div class="message-button">{{ $t("查看更多") }}</div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      messageList: [
        {
          title: "系统消息",
          color: "#909399",
          content:
            "MDN 文档中有大量的指南，这些文章意在增加用例，或教你如何使用 API 接口或特性。此页面将提供到一些最流行的阅读材料的链接。",
          time: "2020-01-01 00:00:00",
          read: false,
          icon: "el-icon-info",
        },
        {
          title: "系统消息",
          color: "#909399",
          content:
            "如何使用 API 接口或特性。此页面将提供到一些最流行的阅读材料的链接。",
          time: "2020-01-01 00:00:00",
          read: false,
          icon: "el-icon-warning",
        },
        {
          title: "审核消息",
          color: "#E6A23C",
          content: "出库订单号: 1234567890",
          time: "2020-01-01 00:00:00",
          read: false,
          icon: "el-icon-question",
        },
        {
          title: "审核成功",
          color: "#67C23A",
          content: "出库订单号: 14798630",
          time: "2020-01-01 00:00:00",
          read: false,
          icon: "el-icon-success",
        },
        {
          title: "错误信息",
          color: "#F56C6C",
          content: "系统出现错误，请重新登录",
          time: "2020-01-01 00:00:00",
          read: false,
          icon: "el-icon-error",
        },
      ],
    };
  },
  computed: {
    read() {
      return this.messageList.filter((item) => item.read).length;
    },
  },
  methods: {
    onRead(item) {
      item.read = true;
    },
  },
};
</script>

<style lang="scss" scoped>
.message-content {
  width: 100%;
  height: 100%;
  background-color: var(--main-bg-color);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  .message-title {
    width: 100%;
    height: 24px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    border-bottom: 1px solid var(--main-border);
    .message-title-text {
      width: 100%;
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      .message-title-text-span {
        width: 100%;
        font-size: 16px;
        font-weight: bold;
        text-align: center;
        color: var(--main-color);
      }
    }
  }

  .message-list {
    width: 100%;
    height: calc(100% - 24px);
    overflow: hidden;
    overflow-y: scroll;

    &::-webkit-scrollbar {
      display: none;
    }

    .message-list-item {
      width: 100%;
      padding: 4px 6px;
      font-size: 12px;
      margin-top: 2px;
      background: transparent;

      &:hover {
        cursor: pointer;
        background: var(--main-shadow);
      }

      .message-list-item-title {
        width: 100%;
        height: 20px;
        display: flex;
        justify-content: space-between;
        align-items: center;

        .title {
          width: 100px;

          & span {
            margin-left: 4px;
          }
        }

        .time {
          font-size: 10px;
          color: var(--sub-title-color);
        }
      }

      .message-list-item-content {
        display: block;
        width: 100%;
        padding: 6px 0px;
        height: 24px;
        overflow: hidden; /* 确保超出容器的文本被隐藏 */
        white-space: nowrap; /* 确保文本在一行内显示 */
        text-overflow: ellipsis; /* 使用省略号表示被截断的文本 */
        color: var(--sub-title-color);
      }
    }
  }

  .message-btn {
    width: 100%;
    height: 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--main-border);

    .message-button {
      width: 50%;
      height: 100%;
      font-size: 14px;
      text-align: center;
      line-height: 24px;
      color: var(--main-color);
    }

    // 样式
    .message-button:hover {
      cursor: pointer;
      background: var(--main-shadow);
      color: var(--main-hover);
    }

    .message-button:nth-child(1) {
      border-right: 1px solid var(--main-border);
    }
  }
}
</style>